package com.example.demo;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 张成
 * @version 1.0
 * @date 2022/3/8 10:47
 */
public class ConfigDemo5Servlet extends HttpServlet {


    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
            throws IOException {
        ServletContext servletContext = getServletContext();
        response.setContentType("text/html;charset=gb2312");
        response.setContentType("text/html;charset=gb2312");
        PrintWriter out = response.getWriter();

        int sum = 0;
        try {
            sum = (int) servletContext.getAttribute("value");
            for (int i = 8; i < 10; i++) {
                sum = sum * i;
            }
            out.println("<html><body>");
            out.println("计算成功 9！=" + sum + "<br>");
            out.println("</body></html>");
        } catch (Exception e) {
            e.printStackTrace();
            out.println("<html><body>");
            out.println("获取失败 请先计算 7！ <br>");
            out.println("</body></html>");
        }



    }
}
